/**
 * Copyright (C) 2010 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.gjc.client.flakytest;

import org.gjc.client.dispatcher.DefaultDispatchAsync;

import com.google.gwt.core.client.GWT;
import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 *
 *
 * @author <a href="mailto:mail@raphaelbauer.com">rEyez</<a>
 *
 */
public class FlankyConnectionTestGwt extends GWTTestCase {

    private static String getTestBaseURL() {
        return GWT.getModuleBaseURL() + "api/";
    }

    @Override
    public String getModuleName() {
        return "org.gjc.FlakyConnectionTestGwt";
    }

    /**
     *
     * The servlet answers does not answer the first time. => A retry has to be
     * in place to make this work => This retry is tested
     *
     */
    public void testFlakyConnection() {

        // get feeditem...
        GetTestAction getFlakyConnectionAction = new GetTestAction();
        //System.out.println("full url: " + getTestBaseURL() + flakyTestUrl);

        DefaultDispatchAsync defaultDispatchAsync = new DefaultDispatchAsync(getTestBaseURL());

        defaultDispatchAsync.execute(getFlakyConnectionAction,
                new AsyncCallback<GetTestResult>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        System.out.println("caught: " + caught);
                        fail();
                        finishTest();
                    }

                    @Override
                    public void onSuccess(GetTestResult result) {
                        assertTrue(true);
                        finishTest();

                    }
                });

        delayTestFinish(100000);
    }

}